export default class Dep {
  subs = [];
  static target = null;
  constructor() {
    // 要侦听的数据
    this.subs = [];
  }
  addSub(sub) {
    // if(this.subs.includes(sub)) this.subs = []
    this.subs.push(sub);
    console.log("subs", this.subs);
  }
  depend() {
    if (Dep.target) {
      console.log("添加订阅者");
      this.addSub(Dep.target);
    }
  }
  notify(newValue,oldValue) {
    console.log("dep通知更新", this.subs);
    // this.subs.forEach((item) => item);
    for (let i = 0; i < this.subs.length; i++) {
      console.log("通知更新的watcher", this.subs);
      this.subs[i].update(newValue,oldValue);
    }
  }
}
